package com.sankuai.velocity;

import android.app.Application;
import android.util.Log;

import org.apache.velocity.app.Velocity;
import org.apache.velocity.runtime.RuntimeConstants;

/**
 * Created by zengliang on 17/3/1.
 */

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        long startTime = System.currentTimeMillis();
        initStringResourceVelocity();
//        initAndroidResourceVelocity();
        Log.i("velocity", "init time: " + (System.currentTimeMillis() - startTime) + "ms");
    }

    private void initStringResourceVelocity() {
        //初始化模板引擎

        //设置日志打印
        Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, "com.sankuai.velocity.VelocityLogger");
        //设置资源加载方式
        Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "string");
        //设置资源加载类
        Velocity.setProperty("string.resource.loader.class", "org.apache.velocity.runtime.resource.loader.StringResourceLoader");
        Velocity.init();
    }


    private void initAndroidResourceVelocity() {
        //初始化模板引擎

        //设置日志打印
        Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, "com.sankuai.velocity.VelocityLogger");
        //设置资源加载方式
        Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "android");
        //设置资源加载类
        Velocity.setProperty("android.resource.loader.class", "com.sankuai.velocity.AndroidResourceLoader");
        Velocity.setProperty("android.content.res.Resources", getResources());
        Velocity.setProperty("packageName", getPackageName());
//        Velocity.setProperty(RuntimeConstants.DEFAULT_RUNTIME_PROPERTIES, "assets/velocity.properties");
//        Velocity.setProperty(RuntimeConstants.DEFAULT_RUNTIME_DIRECTIVES, "assets/directive.properties");
        Velocity.init();
    }
}
